<!--
 * @Descripttion: 打印按钮
-->

<template>
	<div class="sc-button">
		<el-button type="primary" color="#6074e8" v-auth="auth"  @click="batch_export">导出</el-button>
	</div>
</template>

<script>

export default {
	props: {
		apiObj: { type: Object, default: () => {} },
		search: { type: Object, default: () => ({}) },
		auth: { type: String, default: '' },
		params: { type: Object, default: () => ({}) },
		selection: { type: Array, default: () => ([]) },
	},
	data() {
		return {
			searchForm:this.search,
			paramsForm:this.params
		}
	},
	// 监控data中的数据变化
	watch: {
		search:{
			handler(newValue) {
				this.searchForm = newValue
			},
			deep: true// 开启深度监听
		},
	},
	created() {

	},
	methods: {
		/**导出*/
		async batch_export() {
            let ids = []
            this.selection.forEach(item=>{
                ids.push(item.id)
            })
			var res = await this.apiObj.get({
				...this.searchForm,
				export:2,
				...this.paramsForm,
				id:ids
			});
			if (res.code == 2) {
				this.$message.success("导出成功");
				window.location.href = res.data.url
			} else {
				this.$alert(res.message, "提示", {type: "error"});
			}
		},
	}
}
</script>

<style scoped>
.sc-button {
	margin-left: 12px;
}
</style>
